Skip to content

Conversation

toxaart
Copy link
Contributor

@toxaart toxaart commented Aug 22, 2025

Hi, please consider the following changes:

In os_windows.cpp in a few places results returned by GetLastError() are stored to errno. However, errno has no relation to GetLastError(), and their ranges are not the same.

Results of GetLastError() should be stored into variables of type DWORD.

The removed section in src/hotspot/share/cds/aotClassLocation.cpp was relying on values returned by GetLastError() and stored to errno in os::stat(). Though the logic was correct, these values should not be stored to errno. The functionality is preserved by storing a valid value ENOENT to errno in os::stat().

Tested in tiers 1 - 3.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8364816: GetLastError() in os_windows.cpp should not store value to errno (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26901/head:pull/26901
$ git checkout pull/26901

Update a local copy of the PR:
$ git checkout pull/26901
$ git pull https://git.openjdk.org/jdk.git pull/26901/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26901

View PR using the GUI difftool:
$ git pr show -t 26901

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26901.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 22, 2025

👋 Welcome back toxaart! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 22, 2025

@toxaart This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8364816: GetLastError() in os_windows.cpp should not store value to errno

Reviewed-by: dholmes

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 67 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jsikstro, @dholmes-ora) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Aug 22, 2025

@toxaart The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Aug 22, 2025
@toxaart toxaart marked this pull request as ready for review August 26, 2025 14:38
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 26, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 26, 2025

Webrevs

Copy link
Member

@jsikstro jsikstro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one comment but otherwise this looks reasonable!

@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 27, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 27, 2025
Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are never simple. :)

The basic change of not setting errno from GetLastError is good. That is a bug that had to be fixed.

I think your approach for setting errno when callers expect it to be set is also good (but see below). Most callers of os::stat care only about success or failure - not the details of why (which you have recorded in the logging anyway if the user/developer is interested).

You also fixed the aotClassLocation.cpp hack because you should never have to check errno for Windows specific error codes - so that is an extra bonus IMO.

The more general problem of how to map GetLastError to errno when callers expect to check errno, may still remain in other places. That's a separate issue IMO. But I also note that in JDK 8 code we do perform such a mapping where needed (we have more cases to deal with post JDK 8 but it is worth looking at the old code).

However, this has highlighted a giant hole in the way errno is being used: we have cleanup code that will likely overwrite errno before the caller could get to check it! And if cleanup code doesn't then logging code will. This likely affects non-Windows code too - though it may be ErrnoPreserver is being used in enough places there. This seems to be a fairly new problem - I don't see it in JDK 21. I have filed JDK-8366272

I have flagged one thing, in relation to _wopen that needs fixing, but otherwise I think this PR is okay in this form. But then we need the follow up to properly manage errno.

Thanks

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more tweak sorry.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants